<template>
  <div class="login-setting">
    <el-form
      ref="userForm"
      :model="userInfo"
      label-width="120px"
      style="margin-left: 120px; margin-top: 30px"
    >
      <el-form-item label="姓名:" prop="username">
        <el-input v-model="userInfo.username" style="width: 300px" />
      </el-form-item>
      <el-form-item label="密码:" prop="password">
        <el-input
          v-model="userInfo.password"
          style="width: 300px"
          type="password"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="hSbmit">更新</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getUserInfoById, saveUserDetailById } from '@/api/user'
export default {
  data() {
    return {
      userInfo: {
        username: '',
        password: ''
      }
    }
  },
  created() {
    this.loadUserInfoById()
  },
  methods: {
    // 更新用户名和密码
    async hSbmit() {
      try {
        const res = await saveUserDetailById(this.userInfo)
        console.log('saveUserDetailById', res)
        // 调回员工管理页面
        this.$router.back()
      } catch (err) {
        console.log('saveUserDetailById', err)
      }
    },
    // 获取用户个人信息
    async loadUserInfoById() {
      try {
        const res = await getUserInfoById(this.$route.params.id)
        console.log('getUserInfoById', res)
        // 保存数据
        this.userInfo = res.data.data
      } catch (err) {
        console.log('getUserInfoById', err)
      }
    }
  }
}
</script>

<style>

</style>
